package com.ruoyi.common.utils;

import com.ruoyi.framework.config.RuoYiConfig;
import net.ipip.ipdb.CityInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 获取地址类
 *
 * @author ruoyi
 */
public class AddressUtils {

    private static final Logger log = LoggerFactory.getLogger(AddressUtils.class);

    public static String getRealAddressByIP(String ip) {
        String address = "XX XX";
        // 内网不查询
        if (IpUtils.internalIp(ip)) {
            return "内网IP";
        }
        if (RuoYiConfig.isAddressEnabled()) {
            CityInfo cityInfo = IpUtils.getCityInfo(ip);
            address = cityInfo.getRegionName() + " " + cityInfo.getCityName();
        }
        return address;
    }
}
